﻿using D3StatsClient.Model;
using D3StatsClient.ViewModel;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace D3StatsClient.Commands
{
    public class SaveSettings : CommandBase
    {
        public override bool CanExecute(object parameter)
        {
            return true;
        }

        public override void Execute(object parameter)
        {
            var vm = ViewModelManager<SettingsWindowsViewModel>.ViewModel;

            Properties.Settings.Default.PlayOnLegendary = vm.NotifyOnLegendary;
            Properties.Settings.Default.PlayOnRare = vm.NotifyOnRare;
            Properties.Settings.Default.PlayOnMagic = vm.NotifyOnMagic;
            Properties.Settings.Default.LegendarySoundFile = vm.LegendarySoundFile;
            Properties.Settings.Default.RareSoundFile = vm.RareSoundFile;
            Properties.Settings.Default.MagicSoundFile = vm.MagicSoundFile;
            Properties.Settings.Default.PlayOnCrafting = vm.NotifyOnCrafting;
            Properties.Settings.Default.CraftingSoundFile = vm.CraftingSoundFile;
            Properties.Settings.Default.EnableMultiProcessSupport = vm.EnableMultiProcessSupport;

            Guid securityToken = Guid.Empty;

            Guid.TryParse(vm.SecurityToken, out securityToken);

            Properties.Settings.Default.UserSecurityToken = securityToken;
            Properties.Settings.Default.Save();

            //Re-init stuff.
            Sounds.InitSounds();

            vm.Status = "Settings saved successfully.";
        }
    }
}
